package cz.mtq.mgsc.command;

import javax.microedition.lcdui.Displayable;

import cz.mtq.mgsc.MgscMidlet;

/**
 * 
 * <a href="http://minigolfscorecard.googlecode.com/">MiniGolf Scorecard</a>
 * 
 * @author Miroslav Tichý
 *
 */
public abstract class AbstractCommand implements Command {

	private Displayable displayable;
	private javax.microedition.lcdui.Command command;
	private final MgscMidlet midlet;

	public AbstractCommand() {
		this.command = null;
		this.midlet = null;
	}

	public void setCommand(javax.microedition.lcdui.Command command) {
		this.command = command;
	}

	public AbstractCommand(javax.microedition.lcdui.Command command, MgscMidlet midlet) {
		super();
		this.command = command;
		this.midlet = midlet;
	}

	public Displayable getDisplayable() {
		return displayable;
	}

	public void setDisplayable(Displayable displayable) {
		this.displayable = displayable;
	}

	public javax.microedition.lcdui.Command getCommand() {
		return command;
	}

	public MgscMidlet getMidlet() {
		return midlet;
	}

	public void execute() throws Exception {
		exec();
		// dereference displayable
		this.displayable = null;
	}

	protected abstract void exec() throws Exception;

}
